package com.jiyuanime.config;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.jiyuanime.model.PowerMode;
import org.jetbrains.annotations.Nullable;

/**
 * 配置文件
 * Created by KADO on 15/12/17.
 */
@State(name = "activate-power-mode", storages = {@Storage("activate-power-mode.xml")})
public class Config implements PersistentStateComponent<PowerMode> {

    public PowerMode powerMode = new PowerMode();

    @Nullable
    @Override
    public PowerMode getState() {
        return this.powerMode;
    }

    @Override
    public void loadState(PowerMode state) {
        XmlSerializerUtil.copyBean(state, this.powerMode);
    }

    public Config() {
        defaultInitState();
    }

    /**
     * 初始化默认配置
     */
    private void defaultInitState() {
        // 是否开启
        powerMode.isEnable = true;
        // 是否显示火花
        powerMode.isSpark = false;
        // 是否震动
        powerMode.isShake = false;
        // 是否开启 Combo
        powerMode.isCombo = false;
        // 是否开启彩色粒子
        powerMode.isColorful = true;
        // 粒子数量
        powerMode.particleMaxCount = 5;
        // 粒子颜色,为null则代表auto
        powerMode.particleColor = null;
    }

    /**
     * 获取一个配置实例
     *
     * @return Config
     */
    public static Config getInstance() {
        return ServiceManager.getService(Config.class);
    }
}
